package com.fate.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fate.framework.dto.IdParamDTO;
import com.fate.framework.utils.SystemUtil;
import com.fate.system.dto.filepartdetail.FilePartDetailAddDTO;
import com.fate.system.dto.filepartdetail.FilePartDetailPageDTO;
import com.fate.system.dto.filepartdetail.FilePartDetailUpdateDTO;
import com.fate.system.entity.FilePartDetail;
import com.fate.system.service.IFilePartDetailService;
import com.fate.system.vo.filepartdetail.FilePartDetailDetailVO;
import com.fate.system.vo.filepartdetail.FilePartDetailListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "文件分片操作 API")
@RestController
@RequestMapping("/api/v1.0/filePartDetail")
public class FilePartDetailController {

  @Resource private IFilePartDetailService filePartDetailService;

  @Operation(summary = "新增")
  @PostMapping("/add")
  public void add(@RequestBody @Valid FilePartDetailAddDTO addDTO) {
    FilePartDetail filePartDetail = SystemUtil.buildResource(addDTO, FilePartDetail.class);
    filePartDetailService.save(filePartDetail);
  }

  @Operation(summary = "删除")
  @PostMapping("/remove")
  public void remove(@RequestBody @Valid IdParamDTO idParamDTO) {
    filePartDetailService.removeById(idParamDTO.getId());
  }

  @Operation(summary = "更新")
  @PostMapping("/update")
  public void update(@RequestBody @Valid FilePartDetailUpdateDTO updateDTO) {
    FilePartDetail filePartDetail = SystemUtil.buildResource(updateDTO, FilePartDetail.class);
    filePartDetailService.updateById(filePartDetail);
  }

  @Operation(summary = "详情")
  @PostMapping("/detail")
  public FilePartDetailDetailVO detail(@RequestBody @Valid IdParamDTO idParamDTO) {
    FilePartDetail filePartDetail = filePartDetailService.getById(idParamDTO.getId());
    return SystemUtil.buildResource(filePartDetail, FilePartDetailDetailVO.class);
  }

  @Operation(summary = "分页列表")
  @PostMapping("/getPageList")
  public Page<FilePartDetailListVO> getPageList(@RequestBody @Valid FilePartDetailPageDTO pageDTO) {
    Page<FilePartDetail> page = filePartDetailService.getPageList(pageDTO);
    return SystemUtil.buildResource(page, FilePartDetailListVO.class);
  }
}
